﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xinkui.Common.Enum;
using CommonFramework.Utility;
using CommonFramework.Attach;
using Xinkui.Common;
using Back.Xinkui.WebModel;

public partial class Upload : PageAspxBase
{
    protected ESourceType SType
    {
        get
        {
            return (ESourceType)WebHelper.GetQueryStringValue<int>("sType", (int)ESourceType.FromCompanyLogo);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnupload_Click(object sender, EventArgs e)
    {
        try
        {
            if (file1.PostedFile.ContentLength > 0)
            {
                FileSettingEntity fileVaild = FileManger.GetFileSetting((int)SType);
                if (file1.PostedFile.ContentLength > fileVaild.Length)
                {
                    string limitMesage = fileVaild.Length / (1024 * 1024) > 0 ? (fileVaild.Length / (1024 * 1024) + "M") : (fileVaild.Length / 1024 + "kb");
                    Show("上传的图片大小不能超过" + limitMesage + "！");
                    return;
                }
                FileEntity fileentity = Xinkui.Common.FileUpload.Upload(file1.PostedFile, SType, 0, 0);
        
                ////商品及商品描述图片
                //if (SType == ESourceType.fromItemDescription || SType == ESourceType.fromItemPic)
                //{
                //    if (Width == 0 || Heiht == 0)
                //    {
                //        js.Append("var Slides = window.parent.CKEDITOR.instances['" + EditorId + "'].insertHtml(\"<img src='" + FileFactory.GetFilePathByFileArray(fileentity.SavePath.ToLower(), SType).Replace("/uploadimg/", SettingHelper.Settings["OnLineItemImgDomain"]) + "'/>\");\n");
                //    }
                //    else
                //    {
                //        js.Append("var Slides = window.parent.CKEDITOR.instances['" + EditorId + "'].insertHtml(\"<img src='" + FileFactory.GetFilePathByFileArray(fileentity.SavePath.ToLower(), SType, Width, Heiht).Replace("/uploadimg/", SettingHelper.Settings["OnLineItemImgDomain"]) + "'/>\");\n");
                //    }
                //}
                //else
                //{
                //    if (Width == 0 || Heiht == 0)
                //    {
                //        js.Append("var Slides = window.parent.CKEDITOR.instances['" + EditorId + "'].insertHtml(\"<img src='" + FileFactory.GetFilePathByFileArray(fileentity.SavePath.ToLower(), SType).Replace("/upload/", SettingHelper.Settings["OnLineImgDomain"]) + "'/>\");\n");
                //    }
                //    else
                //    {
                //        js.Append("var Slides = window.parent.CKEDITOR.instances['" + EditorId + "'].insertHtml(\"<img src='" + FileFactory.GetFilePathByFileArray(fileentity.SavePath.ToLower(), SType, Width, Heiht).Replace("/upload/", SettingHelper.Settings["OnLineImgDomain"]) + "'/>\");\n");
                //    }
                //}

                ResponseScript("window.close();opener.uploadSuccess(" + SerializationHelper.ObjectToJson(fileentity) + ")");
            }
            else
            {
                Show("请选择上传的文件！");
            }
        }
        catch (Exception ex)
        {
            Show(ex.Message);
        }
    }
}